//
//  Projector.h
//  ___PROJECTNAME___
//
//  Created by Goffredo Marocchi on 8/26/10.
//  Copyright 2010 unofficial_sio2_template. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Math/Matrix.h"
#import "sio2.h"

#define PROJ_TEX (GL_TEXTURE0)
#define FIX_TEX (PROJ_TEX+1)
#define BCULL_TEX (FIX_TEX+1)
#define ATTENUATION_TEX (BCULL_TEX+1)
#define DIFFUSE0_TEX (ATTENUATION_TEX+1)

#define SIO2_TEX0 (GL_TEXTURE5)
#define SIO2_TEX1 (GL_TEXTURE6)

@interface Projector : NSObject {
	
	SIO2camera *projector;
	MATRIX mProjection;
	MATRIX mView;
	MATRIX mTextureProjection;
	MATRIX mBackProjectionFix;
	MATRIX mBackFacesFix;
	MATRIX mBias;
	
	GLuint texture;
	GLuint backprojectionFixTexture;
	GLuint attenuationTexture;
	
	GLubyte *spriteData;
	GLubyte *spriteDataFix;
	GLubyte *spriteDataAtt;
	
	CGImageRef spriteImage;
	size_t     width, height, widthFix, heightFix, attWidth, attHeight;
	
	BOOL updateTextureMap;
}

@property (assign) float aspectRatio;
@property (assign) BOOL updateTextureMap;

-(void) setProjector:(NSString*)sio2Projector;
-(void) calculateProjector;
-(void) submitProjectorGL;
-(void) uploadProjectorTex:(NSString*)file;
-(void) uploadAttenuationTex:(NSString *)file;
-(void) sendVPosAsTexcoords:(SIO2object*)obj_arg;

-(void) rotateZ:(float)angleDeg;

@end
